翻訳と辞書
Words near each other
・ "O" Is for Outlaw
・ "O"-Jung.Ban.Hap.
・ "Ode-to-Napoleon" hexachord
・ "Oh Yeah!" Live
・ "Our Contemporary" regional art exhibition (Leningrad, 1975)
・ "P" Is for Peril
・ "Pimpernel" Smith
・ "Polish death camp" controversy
・ "Pro knigi" ("About books")
・ "Prosopa" Greek Television Awards
・ "Pussy Cats" Starring the Walkmen
・ "Q" Is for Quarry
・ "R" Is for Ricochet
・ "R" The King (2016 film)
・ "Rags" Ragland
・ ! (album)
・ ! (disambiguation)
・ !!
・ !!!
・ !!! (album)
・ !!Destroy-Oh-Boy!!
・ !Action Pact!
・ !Arriba! La Pachanga
・ !Hero
・ !Hero (album)
・ !Kung language
・ !Oka Tokat
・ !PAUS3
・ !T.O.O.H.!
・ !Women Art Revolution


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

increment and decrement operators : ウィキペディア英語版
increment and decrement operators

Increment and decrement operators are unary operators that ''add'' or ''subtract'' one from their operand, respectively. They are commonly implemented in imperative programming languages. C-like languages feature two versions (pre- and post-) of each operator with slightly different semantics.
In languages syntactically derived from B (including C and its various derivatives), the increment operator is written as ++ and the decrement operator is written as --.
The increment operator increases the value of its operand by 1. The operand must have an arithmetic or pointer data type, and must refer to a modifiable data object. Similarly, the decrement operator decreases the value of its modifiable arithmetic operand by 1. Pointers values are increased (or decreased) by an amount that makes them point to the next (or previous) element adjacent in memory.
In languages that support both versions of the operators, the ''pre''-increment and ''pre''-decrement operators increment (or decrement) their operand by 1, and the value of the expression is the resulting incremented (or decremented) value. In contrast, the ''post''-increment and ''post''-decrement operators increase (or decrease) the value of their operand by 1, but the value of the expression is the operand's original value ''prior'' to the increment (or decrement) operation. In languages where increment/decrement is not an expression (e.g. Go), only one version is needed (in the case of Go, post operators only).
Since the increment/decrement operator modifies its operand, use of such an operand more than once within the same expression can produce undefined results. For example, in expressions such as x − ++x, it may not be clear to a user in what sequence the subtraction and increment operations should be performed. Such expressions generally invoke undefined behavior, and should be avoided.
==Examples==
The following C code fragment illustrates the difference between the ''pre'' and ''post'' increment and decrement operators:

int x;
int y;
// Increment operators
x = 1;
y = ++x; // x is now 2, y is also 2
y = x++; // x is now 3, y is 2
// Decrement operators
x = 3;
y = x--; // x is now 2, y is 3
y = --x; // x is now 1, y is also 1


The post-increment operator is commonly used with array subscripts. For example:

// Sum the elements of an array
float sum_elements(float arr[], int n)

Likewise, the post-increment operator is commonly used with pointers:

// Copy one array to another
void copy_array(float
*src, float
*dst, int n)

Note that these examples also work in other C-like languages, such as C++, Java, and C#.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「increment and decrement operators」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.